include layout/header.jade
div.page-content
    div.modal-header
        h4.modal-title 添加标签
    form.form-horizontal(role="form",action="save",method="post")
        div.modal-body.row
            div.col-md-10.col-md-offset-1
                div.form-group
                    label.control-label.col-md-2 标签
                    div.col-md-8
                        input(type='hidden',name='id',value='#{notify._id}')
                        input.form-control(placeholder='标签',name='title',value='#{notify.title}')
                div.form-group
                    label.control-label.col-md-2 正文
                    div.col-md-8
                        div.portlet.box.blue
                            div.portlet-title
                                div.caption 正文
                                input#addImage(type='file',name="file",style="opacity:0;width:0px;",multiple)
                            div#content.portlet-body
                                if notify.content
                                    each val in notify.content
                                        if val.type=="text"
                                            div
                                                textarea.form-control(name="param[]",value="#{val.item}") #{val.item}
                                                p
                                                    input(type='hidden',name='type[]',value='text')
                                                    a.btn.blue.insertText(type="button") 插入文字
                                                    a.btn.blue.insertImg(type="button") 插入图片
                                                    a.btn.red.delete(type="button") 删除
                                        else
                                            div
                                                image.img-thumbnail(name="param[]",src="#{val.item}")
                                                p
                                                    input(type='hidden',name='type[]',value='img')
                                                    a.btn.blue.insertText(type="button") 插入文字
                                                    a.btn.blue.insertImg(type="button") 插入图片
                                                    a.btn.red.delete(type="button") 删除
                                else
                                    div
                                        textarea.form-control(name="param[]")
                                        p
                                            input(type='hidden',name='type[]',value='text')
                                            a.btn.blue.insertText(type="button") 插入文字
                                            a.btn.blue.insertImg(type="button") 插入图片
                                            a.btn.red.delete(type="button") 删除
        div.modal-footer
            div.col-md-10.col-md-offset-1
                div.col-md-8.col-md-offset-2
                    a.btn.green(href="./") 取消
                    button.btn.green(type="submit") 保存
script(type='text/javascript').
      aoColumnDefs = [];
include layout/footer.jade
script(type='text/javascript').
    $(document).ready(function(){
        var currentBtn = null;
        $("#content").on('click','.delete',function(){
                $(this).parent().parent().remove();
                
            });
        $("#content").on('click','.insertText',function(){
            var textarea = $("<div></div>").append("<textarea name='param[]' class='form-control'></textarea><p><input type='hidden' name='type[]' value='text'><a class='btn blue insertText'>插入文字</a><a class='btn blue insertImg'>插入图片</a><a class='btn red delete'>删除</a>")
                textarea.insertAfter($(this).parent().parent());
            });
        $("#content").on('click','.insertImg',function(){
                currentBtn = $(this).parent().parent();
                $("#addImage").click();
            });
       $("#addImage").fileupload({
           url:"/file-upload",
           autoUpload:true,
           done:function(e,data){
                var image = $("<div></div>").append("<image class='img-thumbnail' src=/"+data.result.path+"><p><input type='hidden' name='param[]' value='/"+data.result.path+"'><input type='hidden' name='type[]' value='img'><a class='btn blue insertText'>插入文字</a><a class='btn blue insertImg'>插入图片</a><a class='btn red delete'>删除</a>")
               image.insertAfter(currentBtn);
           }
        });
    });